EndType
Type <.typeName.> [As <.typeName.>] ... EndType
 
Parameters: NONE
Returns: NONE
 

      You can define your own data types with Type. User defined types in PlayBASIC are very similar to Structs in C or Records in Pascal and contain one or more Fields. A simple type definition would look like this:

  
  Type TMyType
     Field1
     Field2#
     Field3$
  EndType
  


      This declares a user defined type called TMyType that contains three fields. An integer field called Field1, a float field called Field2# and a string field called Field3$. In order to use this type you need to delcare a variable with this type:

  
  Dim MyNewVar As TMyType
  


     You can also delcare an array

  
  Dim MyNewArray(10As TMyType
  



     To access each defined type field of the new variable you type the variable name followed by a dot (.) and then the field name:

  
  MyNewVar.Field1 = 42
  MyNewVar.Field2# = 1.2345
  MyNewVar.Field$ = "PlayBASIC"
  
  MyNewArray(4).Field1 = 456
  ...
  



     Each field of a type can either be of a basic type (Integer, Float or String) or a previously user defined type:

  
  Type TPoint
     X
     Y
  EndType
  Type TPlayer
     Name$
     Position As TPoint
     Health
  EndType
  
  Dim MyPlayer As TPlayer
  MyPlayer.Name$ = "Hero"
  MyPlayer.Position.X = 12
  MyPlayer.Position.Y = 200
  MyPlayer.Health = 100
  



     PlayBASIC offers another feature called Inherited Types. That means that you can inherit the fields of a previously defined type in a new type.

Example:

  
  Type TNameAge
     Name$
     Age
  EndType
  
  Type TAllDetails As TNameAge
     Address$
     FavouriteColour$
     Weight#
  EndType
  


     With As statement the type "TAllDetails" inherits all the fields of "TNameAge". Therefore the type "TAllDetails" has the following fields:

  
  Name$
  Age
  Address$
  FavouriteColour$
  Weight#
  



To learn more about Types please read the Types Tutorial





 
Related Info: Dim | List | Pointer | Type | TypeOf | Types :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com